package com.wt.struggle.goodbye.user.activity

import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import com.google.gson.reflect.TypeToken
import com.wt.struggle.goodbye.R
import com.wt.struggle.goodbye.base.Config
import com.wt.struggle.goodbye.base.ProActivity
import com.wt.struggle.goodbye.base.Send
import com.wt.struggle.goodbye.info.NetInfo
import com.wt.struggle.goodbye.info.NewsInfo
import com.wt.struggle.goodbye.sq.adapter.PickUserAdapter
import com.xin.lv.yang.utils.line.DividerItemDecoration
import kotlinx.android.synthetic.main.head.*
import kotlinx.android.synthetic.main.share_list_layout.*

/**
 * 分享 转载
 */
class ShareListActivity : ProActivity() {

    override fun handler(what: Int, arg1: Int, netInfo: NetInfo) {
        when (what) {
            Send.SEARCH_LIST -> {
                removeLoadDialog()
                if (netInfo.code == Config.SUCCESS) {
                    val result = netInfo.dataResult
                    if (result != null && result != "" && result != "null") {
                        val arr = gson!!.fromJson<ArrayList<NewsInfo>>(
                            result,
                            object : TypeToken<ArrayList<NewsInfo>>() {}.type
                        )

                        adapter.updateData(arr)

                    }
                }
            }
        }
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.share_list_layout)
        tvTitle.text = "分享转载"
        imageBack.setOnClickListener {
            finish()
        }

        initAdapter()

        send!!.getShareList(page, 1, handler!!)
        showLoadDialog()

    }


    var page = 1
    val list = arrayListOf<NewsInfo>()

    lateinit var adapter: PickUserAdapter


    private fun initAdapter() {
        shareRecyclerView.layoutManager = LinearLayoutManager(this)
        shareRecyclerView.addItemDecoration(
            DividerItemDecoration(
                this,
                DividerItemDecoration.VERTICAL_LIST,
                R.drawable.share_list_line
            )
        )
        adapter = PickUserAdapter(this, list)
        adapter.isEnterCode = 3

        shareRecyclerView.adapter = adapter
    }
}